package com.example.testproj.design.composite;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * @des:
 * @author: 芮勤
 * @date: 2019/6/17 16:03
 * @see {@link }
 */
public class Composite extends Component {
    private List<Component> children = new ArrayList<>();

    public Composite(String name) {
        super(name);
    }

    @Override
    public void Add(Component c) {
        children.add(c);
    }

    @Override
    public void Remove(Component c) {
        children.remove(c);
    }

    @Override
    public void Display(int depth) {

        String split="";
        for (int i=0;i<depth;i++){
            split+="-";
        }
        Log.d(TAG, "Display: " + split + name);
        for (Component c :
                children) {
            c.Display(depth + 2);
        }
    }
}
